import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:pax_info_app/config/constants.dart';

/**
 * Log 拦截器
 * Created by zongjian
 * Date: 2019-06-18
 */
class LogsInterceptors extends InterceptorsWrapper {
  @override
  onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
    if (Constants.DEBUG) {
      debugPrint('HTTP 请求url: ${options.path}');
      debugPrint('HTTP 请求头: ${options.headers.toString()}');
      if (options.data != null) {
        debugPrint('HTTP 请求参数: ${options.data.toString()}');
      }
    }
    return super.onRequest(options, handler);
  }

  @override
  onResponse(Response response, ResponseInterceptorHandler handler) async {
    if (Constants.DEBUG) {

        debugPrint('HTTP 返回参数: ' + response.toString());

    }

    return super.onResponse(response, handler);
  }

  @override
  onError(DioError err, handler) async {
    if (Constants.DEBUG) {
      debugPrint('HTTP 请求异常: ' + err.toString());
    }
    return super.onError(err, handler);
  }


}
